#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	int a[n];
	bool b[n];
	int RMax = 0;
	for(int i=0; i<n; i++ ){
		cin >> a[i];
		if( a[i]>RMax ) {
			RMax = a[i];
			b[i] = true;
		}else b[i] = false;
	} 
	vector<int> res;
	int LMin = a[n-1] + 1;
	for(int i=n-1; i>=0; i--){
		if( a[i]<LMin ) {
			LMin = a[i];
			if( b[i] ) 	res.push_back(a[i]);
		}
	}
	sort(res.begin(),res.end());
	cout << res.size() << endl;
	for(int i=0; i<res.size(); i++ ) cout << (i==0?"":" ") << res[i];
	cout << "*";
	return 0;
}
